package cn.edu.zust.se.shop.service.impl;

import cn.edu.zust.se.shop.dao.UserRepository;
import cn.edu.zust.se.shop.domain.User;
import cn.edu.zust.se.shop.dto.UserDto;
import cn.edu.zust.se.shop.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    UserRepository userDao;
    @Override
    public UserDto getUserById(Integer userId) {
        User user=userDao.getOne(userId);

        UserDto dto=new UserDto();
        if(user!=null)
            BeanUtils.copyProperties(user,dto);
        return dto;
    }
    @Override
    public UserDto login(UserDto userDto){
        User user=userDao.findUserByUAndUsernameAndPassword(userDto.getUsername(),userDto.getPassword());
        if(user==null)
            return null;
        UserDto dto=new UserDto();
        BeanUtils.copyProperties(user,dto);
        return dto;
    }
}
